//-----------------------------------------------------------------------------
//	File: led.c
//	Author: hsia
//		bsp of led
//-----------------------------------------------------------------------------

#include "led.h"

#define LED_RCC_ALL		RCC_APB2Periph_GPIOD
#define LED_PORT		GPIOD
#define LED_PIN			GPIO_Pin_9

//-----------------------------------------------------------------------------
//	configure_led_gpio - configure led gpio
//-----------------------------------------------------------------------------
void configure_led_gpio(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	// Enable the peripheral's clock
	RCC_APB2PeriphClockCmd(LED_RCC_ALL, ENABLE);
	// gpio default
	led(0);
	// gpio mode
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	// led pin seting
	GPIO_InitStructure.GPIO_Pin = LED_PIN;
	GPIO_Init(LED_PORT, &GPIO_InitStructure);
}

//-----------------------------------------------------------------------------
//	led on off inv
//-----------------------------------------------------------------------------
void led(uint8_t sw)
{
	switch (sw) {
		case 0: LED_PORT->ODR |= LED_PIN; break;
		case 1: LED_PORT->ODR &= ~LED_PIN; break;
		case 2: LED_PORT->ODR ^= LED_PIN; break;
	}
}

